package com.jhgsys.internal.sypq.service.impl;

import com.jhgsys.internal.sypq.entity.TaskTestbl2;
import com.jhgsys.internal.sypq.mapper.TaskTestbl2Mapper;
import com.jhgsys.internal.sypq.service.ITaskTestbl2Service;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.system.entity.User;
import org.apache.shiro.SecurityUtils;
import com.jhgsys.internal.common.entity.FebsConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 伴流-桨模 Service实现
 *
 * @author ganjun
 * @date 2024-12-11 00:53:32
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TaskTestbl2ServiceImpl extends ServiceImpl<TaskTestbl2Mapper, TaskTestbl2> implements ITaskTestbl2Service {

    /**
     * 查询（分页）
     * @author ganjun
     * @date 2024-12-11 00:53:32
     * @param request QueryRequest
     * @param taskTestbl2 taskTestbl2
     * @return IPage<TaskTestbl2>
    */
    @Override
    public IPage<TaskTestbl2> findTaskTestbl2Page(QueryRequest request, TaskTestbl2 taskTestbl2) {
        LambdaQueryWrapper<TaskTestbl2> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestbl2::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<TaskTestbl2> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author ganjun
     * @date 2024-12-11 00:53:32
     * @param taskTestbl2 taskTestbl2
     * @return List<TaskTestbl2>
     */
    @Override
    public List<TaskTestbl2> findTaskTestbl2List(TaskTestbl2 taskTestbl2) {
	    LambdaQueryWrapper<TaskTestbl2> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestbl2::getDeletedFlg, 0);
        queryWrapper.eq(TaskTestbl2::getTaskcode,taskTestbl2.getTaskcode());
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author ganjun
    * @date 2024-12-11 00:53:32
    * @param id
    * @return TaskTestbl2
    */
    @Override
    public TaskTestbl2 findTaskTestbl2ById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author ganjun
     * @date 2024-12-11 00:53:32
     * @param taskTestbl2 taskTestbl2
     */
    @Override
    @Transactional
    public boolean createTaskTestbl2(TaskTestbl2 taskTestbl2) {
        return this.save(taskTestbl2);
    }

    /**
     * 修改
     * @author ganjun
     * @date 2024-12-11 00:53:32
     * @param taskTestbl2 taskTestbl2
     */
    @Override
    @Transactional
    public boolean updateTaskTestbl2(TaskTestbl2 taskTestbl2) {
        return this.updateById(taskTestbl2);
    }

    /**
     * 逻辑删除
     * @author ganjun
     * @date 2024-12-11 00:53:32
     * @param taskTestbl2 taskTestbl2
     * @param taskTestbl2Ids taskTestbl2Ids
     */
    @Override
    @Transactional
    public boolean deleteTaskTestbl2(TaskTestbl2 taskTestbl2,String taskTestbl2Ids) {
        boolean result = false;
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        List<String> list = Arrays.asList(taskTestbl2Ids.split(StringPool.COMMA));

        taskTestbl2.setDeletedBy(user.getUserName());
        taskTestbl2.setDeletedTime(new Date());
        taskTestbl2.setDeletedFlg(FebsConstant.INVALID);
        int update = this.baseMapper.update(taskTestbl2,new LambdaQueryWrapper<TaskTestbl2>().in(TaskTestbl2::getId,list));
        if (update > 0 ){
            result = true;
        }
        return result;
	}

    /**
    * 物理删除
    * @author ganjun
    * @date 2024-12-11 00:53:32
    * @param taskTestbl2Ids taskTestbl2Ids
    */
    @Override
    @Transactional
    public boolean physicallyDeleteTaskTestbl2(String taskTestbl2Ids) {
        List<String> list = Arrays.asList(taskTestbl2Ids.split(StringPool.COMMA));
        LambdaQueryWrapper<TaskTestbl2> wapper = new LambdaQueryWrapper<>();
        wapper.in(TaskTestbl2::getId,list);
        return this.remove(wapper);
    }
}
